Skip to content

added the 5 functions to test#10

Open
davisgd wants to merge 2 commits intoAmericaCampaign:masterfrom
davisgd:data-and-functions-1
Open

added the 5 functions to test#10
davisgd wants to merge 2 commits intoAmericaCampaign:masterfrom
davisgd:data-and-functions-1

Conversation

@davisgd
Copy link

@davisgd davisgd commented Aug 23, 2017

No description provided.


const getProductById = (id) => {
let product
for (let n = 0; n < DATA.products.length; n += 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's standard practice to use the variable name i in a for loop.

@@ -0,0 +1,13 @@
import DATA from '../DATA'

const getProductById = (id) => {
Copy link
Contributor

@jcheroske jcheroske Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected function signature is:

const getProductById = (data, productId) => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to test to make sure data, data.products, and productId are not null.

@@ -0,0 +1,13 @@
import DATA from '../DATA'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to import the data, since the test will pass it in as the first parameter.

return null
} else {
DATA.users.forEach((u) => {
if (u.userId === DATA.id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want to test against DATA.id. What is the correct comparison?

if (u.userId === ???) { // <-- What do we really want to compare `u.userId` against?

@@ -0,0 +1,13 @@
import DATA from '../DATA'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to pass in the data. The first parameter of all of your functions should be the data.

@@ -0,0 +1,13 @@
import DATA from '../DATA'

const getActiveUsers = (id) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a data parameter as the first parameter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check the parameters according to the getActiveUsers.test.js file.

@@ -0,0 +1,17 @@
import DATA from '../DATA'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the import.

import DATA from '../DATA'

const getMostExpensiveProduct = (data) => {
if (data == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is correct, but you need one more I think.

if (data == null) {
return null
}
let mostExpensiveProduct = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many ways to solve this one. You need to declare a variable like you did, but let's not initialize it: let mostExpensiveProduct

return null
}
let mostExpensiveProduct = 0
DATA.products.forEach((m) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The forEach loop passes in the actual object as the first param to your function. Instead of calling it m, call it currentProduct

}
let mostExpensiveProduct = 0
DATA.products.forEach((m) => {
const currentProduct = data.products[m]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line.

let mostExpensiveProduct = 0
DATA.products.forEach((m) => {
const currentProduct = data.products[m]
if (currentProduct.price > mostExpensiveProduct) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things need to change here:

  1. You should test to see if mostExpensiveProduct == null. OR:
  2. Compare the prices of the currentProduct and the mostExpensiveProduct

If either of those are true, enter your if

return null
}
const orderArray = []
DATA.orders.forEach((o) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the o parameter with currentOrder

}
const orderArray = []
DATA.orders.forEach((o) => {
const currentOrder = DATA.orders[o]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this

@jcheroske
Copy link
Contributor

I added lots of comments to your code! Take a look. If you're confused in any way, please reach out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments